// pages/task/task.js
Page({

    data: {

        token:"",

        Title:[ 
            {
                id:0,
                name:"地点"
            },
            {
                id:1,
                name:"期望时间"
            },
            {
                id:2,
                name:"基本要求"
            },
            {
                id:3,
                name:"赏金"
            }
        ],

        taskorder:[]

    },

    takeorder:function(e){

        var that = this

        wx.showModal({
          title:"接单",
          content:"是否接受订单",
          success(res){
              if(res.confirm){
                wx.request({
                  url: 'http://119.23.252.15:10002/task/receiveOrder',
                  method:"POST",
                  data:{
                      token : wx.getStorageSync('token'),
                      orderId : e.currentTarget.id
                  },
                  success(res){
                    if(res.data.status){
                        that.onLoad()
                        wx.showToast({
                          title: '成功接受订单',
                        })
                        }
                        else{
                            wx.showToast({
                              title: '接受订单失败 似乎出现了什么BUG',
                            })
                        }
                  }
                })
              }
              else if (res.cancel) 
              {
                  console.log('不接单')
              }
          },
          
        })
    },


    //发送token获取待接订单信息
    onLoad: function () {
        console.log("token:"+wx.getStorageSync('token'))

        var that = this

        wx.request({
          url: 'http://119.23.252.15:10002/task/unreceiveOrderList',
          method:"POST",
          data:{
            token:wx.getStorageSync('token')
          },
          success(res){
              that.setData({
                  taskorder:res.data.data.unreceiveOrderList,
              })
          }
        })
    },
})